import type { FieldConfig } from '@/components/TableFilter.vue'
import { getFormFields } from '@/utils/formUtils'
import type { FormFieldConfig } from '@/types/form'
import { getConsultPlanOptions } from './doctorConsultPlan'

// 表格列配置
export const tableColumns = [
  {
    title: 'ID',
    dataIndex: 'id',
  },
  {
    title: '醫生姓名',
    dataIndex: 'name',
  },
  {
    title: '員工編號',
    dataIndex: 'staffCode',
  },
  {
    title: 'POS服務編號',
    dataIndex: 'productCode',
  },
  {
    title: '員工類型',
    dataIndex: 'staffType',
  },
  {
    title: '當前駐診形式',
    dataIndex: 'currentShift',
  },
  {
    title: '狀態',
    dataIndex: 'status',
  },
  {
    title: '最後修改時間',
    dataIndex: 'updatedAt',
  },
  {
    title: '操作',
    key: 'action',
    align: 'center',
  },
]
// 過濾項配置
export const filterFields: FieldConfig[] = [
  {
    name: 'staff_code',
    label: '員工編號',
    type: 'input',
    placeholder: '請輸入員工編號',
  },

  {
    name: 'name',
    label: '醫生姓名',
    type: 'input',
    placeholder: '請輸入醫生姓名',
  },
  {
    name: 'product_code',
    label: 'POS服務編號',
    type: 'input',
    placeholder: '請輸入POS服務編號',
  },
  {
    name: 'satff_type',
    label: '員工類別',
    type: 'select',
    options: [
      { value: '', label: '全部' },
      { value: 1, label: '合作' },
      { value: 2, label: '員工' },
    ],
  },
  {
    name: 'current_shift',
    label: '當前駐診形式',
    type: 'select',
    options: [
      { value: '', label: '全部' },
      { value: 1, label: '全日' },
      { value: 2, label: '半日' },
    ],
  },
]


// 表單字段配置
const FormField: Record<string, FormFieldConfig> = {
  name: {
    label: '醫生姓名',
    type: 'input',
    placeholder: '請輸入醫生姓名',
    rules: [{ required: true, message: '請輸入醫生姓名' }],
  },
  staffCode: {
    label: '員工編號',
    type: 'input',
    placeholder: '請輸入員工編號',
    rules: [{ required: true, message: '請輸入員工編號' }],
  },
  productCode: {
    label: 'POS服務編號',
    type: 'input',
    placeholder: '請輸入醫生服務編碼',
    rules: [{ required: true, message: '請輸入醫生服務編碼' }],
  },
  staffType: {
    label: '員工類別',
    type: 'radio',
    options: [
      { key: 2, label: '員工' },
      { key: 1, label: '合作' },
    ],
    defaultValue:2
  },
  currentShift: {
    label: '當前駐診形式',
    type: 'radio',
    options: [
      { key: 1, label: '全日' },
      { key: 2, label: '半日' },
    ],
    defaultValue:1
  },
  hireDate: {
    label: '入職日期',
    type: 'date',
    placeholder: '請選擇入職日期',
    rules: [{ required: true, message: '請選擇入職日期' }],
  },
  lastDate:{
    label: '離職日期',
    type: 'date',
    placeholder: '請選擇離職日期',
    rules: [{ required: false, message: '請選擇離職日期' }],
  },
  consultPlanId: {
    label: '診金分成方案',
    type: 'select',
    placeholder: '請選擇診金分成方案',
    rules: [{ required: true, message: '請選擇診金分成方案' }],
    options: [],
  },
  hasConsultShare: {
    label: '是否診金分成',
    type: 'switch',
  },
  hasAdditionalShare: {
    label: '是否附加項目分成',
    type: 'switch',
  },
  hasRegularShare: {
    label: '是否常規銷售分成',
    type: 'switch',
  },
  hasExtraShare: {
    label: '是否附加推廣分成',
    type: 'switch',
  },
  hasBonus:{
    label: '是否獎金分成',
    type: 'switch',
  },
  viewShareRecord:{
    label: '查看分成記錄',
    type: 'switch',
  }

}

// 創建表單字段
export const getCreteFieldConfig = async(fields?: string[]) => {
  fields = fields || ['name','staffCode','consultPlanId','productCode','staffType','currentShift','hireDate']
  if(fields.includes('consultPlanId')){
      const consultPlanOptions = await getConsultPlanOptions()
      FormField.consultPlanId.options = consultPlanOptions
  }
  return getFormFields(FormField, fields)
}

export const getEditFieldConfig = (fields?: string[]) => {
  fields = fields || ['productCode','hireDate','lastDate']
  return getFormFields(FormField, fields)
}

export const getRightFieldConfig = (fields?: string[]) => {
  fields = fields || ['hasConsultShare','hasAdditionalShare','hasRegularShare','hasExtraShare','hasBonus','viewShareRecord']
  return getFormFields(FormField, fields)
}



const recountFormField: Record<string, FormFieldConfig> = {
  type: {
    label: '核算類型',
    type: 'select',
    options: [
      { key: 1, label: '佣金' },
      { key: 2, label: '獎金' },
    ],
    defaultValue:1
  },
  statMonth:{
    label: '統計月份',
    type: 'date-picker',
    placeholder: '請選擇統計月份',
    picker: 'month',
  }
  
}


export const getRecountFieldConfig = (fields?: string[]) => {
  return getFormFields(recountFormField, fields)
}
